home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / IMAGEN.TRM < prev    next >
Text File  |  1992-03-25  |  8KB  |  343 lines

  1. /*
  2.  * $Id: imagen.trm,v 3.26 92/03/24 22:35:33 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - imagen.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   Imagen laser printers
  25.  *
  26.  * AUTHORS
  27.  *   Paul E. McKenney, David Kotz
  28.  * 
  29.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  30.  * 
  31.  */
  32.  
  33. /*
  34.  * Original for direct Imagen output (but retaining many of the
  35.  * LaTeX extensions) by Paul E. McKenney, 1989.
  36.  * Further modified by David Kotz to fit into gnuplot 2.0.
  37.  * Information Science and Technology Division, SRI International,
  38.  * 333 Ravenswood Ave, Menlo Park, CA 94025.
  39.  * Mail to mckenney@sri.com.
  40.  */
  41.  
  42. #include "impcodes.h"
  43.  
  44. #define IMAGEN_PTS_PER_INCH (300)
  45.  
  46. #define IMAGEN_XMAX (IMAGEN_PTS_PER_INCH * 10) /* 10.0 inches */
  47. #define IMAGEN_YMAX (IMAGEN_PTS_PER_INCH * 75 / 10) /* 7.5 inches */
  48.  
  49. #define IMAGEN_FONTSIZE 12
  50.  
  51. #define IMAGEN_HTIC (20)
  52. #define IMAGEN_VTIC (20)
  53. #define IMAGEN_VCHAR (IMAGEN_FONTSIZE*5)
  54. #define IMAGEN_HCHAR (IMAGEN_VCHAR/2)
  55.  
  56. static int IMAGEN_orgx;        /* absolute-pixel-ORIgin of graph.    */
  57. static int IMAGEN_orgy;
  58. static int IMAGEN_posx;        /* current drawing position (lines).    */
  59. static int IMAGEN_posy;
  60. static int IMAGEN_inplot;
  61. static int IMAGEN_xmax;        /* width of graph in pixels.        */
  62. static int IMAGEN_ymax;        /* height of graph in pixels.        */
  63. static int IMAGEN_hchar;        /* Height of CHAR in current font.    */
  64. static int IMAGEN_wchar;        /* Width of CHAR in current font.    */
  65. static int IMAGEN_blofs;        /* BaseLine OFfSet from bounding box.    */
  66. static int IMAGEN_angle = -1;    /* 0 for horizontal text, 1 for vertical */
  67. static enum JUSTIFY IMAGEN_justify = LEFT; /* left/center/right */
  68.  
  69. static IMAGEN_seq_pos;        /* position in sequence */
  70.  
  71. static void IMAGEN_putwd();
  72. static void IMAGEN_createfamily();
  73. static void IMAGEN_setfont();
  74. static void IMAGEN_setpos();
  75. static char *IMAGEN_cvts();
  76.  
  77. IMAGEN_init()
  78. {
  79.     char font[10];            /* font name */
  80.  
  81.     IMAGEN_posx = IMAGEN_posy = 0;
  82.  
  83.     IMAGEN_orgx = (11.0 * IMAGEN_PTS_PER_INCH - IMAGEN_XMAX) / 2;
  84.     IMAGEN_orgy = (8.5 * IMAGEN_PTS_PER_INCH - IMAGEN_YMAX)/ 2;
  85.  
  86.     fputs("@document(language impress)", outfile);
  87.  
  88.     putc(imP_SET_HV_SYSTEM, outfile);
  89.     putc((3<<3)|5, outfile);
  90.  
  91.     sprintf(font, "cour%02d", IMAGEN_FONTSIZE);
  92.     IMAGEN_createfamily(font, IMAGEN_FONTSIZE);
  93.     IMAGEN_setfont(IMAGEN_FONTSIZE);
  94.  
  95.     IMAGEN_text_angle(0);
  96.  
  97.     putc(imP_SET_ABS_H, outfile);
  98.     IMAGEN_putwd(0);
  99.     putc(imP_SET_ABS_V, outfile);
  100.     IMAGEN_putwd(0);
  101.  
  102.     IMAGEN_linetype(-1);
  103. }
  104.  
  105. IMAGEN_graphics()
  106. {
  107.     static BOOLEAN first = TRUE;
  108.  
  109.     if (!first)
  110.      putc(imP_ENDPAGE, outfile);
  111.     first = FALSE;
  112.  
  113.     IMAGEN_move(0, 0);
  114. }
  115.  
  116. IMAGEN_text()
  117. {
  118. }
  119.  
  120.  
  121. IMAGEN_linetype(linetype)
  122. int linetype;
  123. {
  124.     static int lastlinetype = -10;
  125.  
  126.     if (linetype < 0)
  127.      linetype = -linetype;
  128.     else
  129.      linetype *= 2;
  130.  
  131.     if (lastlinetype == linetype)
  132.      return;
  133.  
  134.     lastlinetype = linetype;    /* now >= 0 */
  135.  
  136.     putc(imP_SET_PEN, outfile);
  137.     putc(linetype, outfile);
  138. }
  139.  
  140.  
  141. IMAGEN_move(x,y)
  142.     unsigned int x,y;
  143. {
  144.     IMAGEN_posx = x;
  145.     IMAGEN_posy = y;
  146. }
  147.  
  148. IMAGEN_vector(ux,uy)
  149.     unsigned int ux,uy;
  150. {
  151.     /* Create path. */
  152.  
  153.     putc(imP_CREATE_PATH, outfile);
  154.     IMAGEN_putwd(2);
  155.     IMAGEN_putwd(IMAGEN_posx + IMAGEN_orgx);
  156.     IMAGEN_putwd(IMAGEN_posy + IMAGEN_orgy);
  157.     IMAGEN_putwd(ux + IMAGEN_orgx);
  158.     IMAGEN_putwd(uy + IMAGEN_orgy);
  159.  
  160.     /* Draw path with black pen. */
  161.  
  162.     putc(imP_DRAW_PATH, outfile);
  163.     putc(15, outfile);
  164.  
  165.     /* Set current position to end of line. */
  166.  
  167.     IMAGEN_move(ux, uy);
  168. }
  169.  
  170. static void
  171. IMAGEN_setpos(ux, uy)
  172.     int ux,uy;
  173. {
  174.     /* Set x and y position (for text), also set beginning-of-line. */
  175.  
  176.     putc(imP_SET_ABS_H, outfile);
  177.     IMAGEN_putwd(ux + IMAGEN_orgx);
  178.     putc(imP_SET_ABS_V, outfile);
  179.     IMAGEN_putwd(uy + IMAGEN_orgy);
  180.     putc(imP_SET_BOL, outfile);
  181.     if (IMAGEN_angle == 1)
  182.      IMAGEN_putwd(uy + IMAGEN_orgx); /* vertical */
  183.     else
  184.      IMAGEN_putwd(ux + IMAGEN_orgx); /* horizontal */
  185. }
  186.  
  187. IMAGEN_text_angle(angle)
  188.     int angle;
  189. {
  190.     if (IMAGEN_angle != angle) {
  191.        IMAGEN_angle = angle;    /* record for later use */
  192.        putc(imP_SET_ADV_DIRS, outfile);
  193.        putc(angle == 0 ? 0 : 7, outfile); /* 0=>horiz : 7=>vert */
  194.     }
  195.  
  196.     return(TRUE);
  197. }
  198.  
  199. IMAGEN_justify_text(mode)
  200.     enum JUSTIFY mode;
  201. {
  202.     IMAGEN_justify = mode;
  203.     return(TRUE);
  204. }
  205.  
  206. static char *
  207. IMAGEN_cvts(str, width, height)
  208.     char        *str;
  209.     int        *width;
  210.     int        *height;
  211. {
  212.     char        *cp1;
  213.     char        *cp2;
  214.     static char    *buf = NULL;
  215.     int        h;
  216.     int        maxw;
  217.     int        w;
  218.  
  219.     /* Free up old buffer, if there is one, get a new one.  Since    */
  220.     /* all transformations shorten the string, get a buffer that is    */
  221.     /* the same size as the input string.                */
  222.  
  223.     if (buf != NULL)
  224.      (void) free(buf);
  225.     buf = (char *) alloc(strlen(str), "converted label string");
  226.  
  227.     /* Do the transformations. */
  228.  
  229.     cp1 = str;
  230.     cp2 = buf;
  231.     h = 1;
  232.     maxw = 0;
  233.     w = 0;
  234.     while (strlen(cp1) > 0) {
  235.        switch (*cp1) {
  236.           case ' ' :        /* Space character. */
  237.             *cp2++ = imP_SP;
  238.             w++;
  239.             break;
  240.             
  241.             case  '\\' :    /* Escape sequence. */
  242.              if (*++cp1 == '\\') {
  243.                 /* Begin new line. */
  244.                 h++;
  245.                 if (w > maxw)
  246.                   maxw = w;
  247.                 w = 0;
  248.                 *cp2++ = imP_CRLF;
  249.                 break;
  250.              }
  251.             
  252.             /* Fall through to just copy next char out.    */
  253.             
  254.             default :
  255.              *cp2++ = *cp1;
  256.             w++;
  257.             break;
  258.         }
  259.        cp1++;
  260.     }
  261.     
  262.     *cp2 = '\0';
  263.     if (w > maxw)
  264.      maxw = w;
  265.     
  266.     if (height != NULL)
  267.      *height = IMAGEN_angle ?
  268.        IMAGEN_wchar * maxw :
  269.         IMAGEN_hchar * h;
  270.     if (width != NULL)
  271.      *width = IMAGEN_angle ?
  272.        IMAGEN_hchar * h :
  273.         IMAGEN_wchar * maxw;
  274.     return (buf);
  275. }
  276.  
  277. IMAGEN_put_text(x, y, str)
  278.     int x,y;                /* reference point of string */
  279.     char str[];            /* the text */
  280. {
  281.     char *cvstr;
  282.     int height;
  283.     int width;
  284.     
  285.     cvstr = IMAGEN_cvts(str, &width, &height);
  286.  
  287.     switch (IMAGEN_justify) {
  288.        case LEFT: break;
  289.        case CENTRE: x -= width/2; break;
  290.        case RIGHT: x -= width; break;
  291.     }
  292.  
  293.     if (IMAGEN_angle) {        /* vertical */
  294.        x += IMAGEN_hchar;
  295.        y -= height/2;
  296.     } else                /* horizontal */
  297.      y += height/2 - IMAGEN_hchar;
  298.  
  299.     IMAGEN_setpos(x, y + IMAGEN_blofs);
  300.     fputs(cvstr, outfile);
  301. }
  302.  
  303.  
  304. IMAGEN_reset()
  305. {
  306.     putc(imP_EOF, outfile);
  307. }
  308.  
  309. static void
  310. IMAGEN_putwd(w)
  311. {
  312.     putc(w>>8, outfile);
  313.     putc(w, outfile);
  314. }
  315.  
  316. static void
  317. IMAGEN_createfamily(c, sz)
  318.     char        *c;
  319.     int        sz;
  320. {
  321.     putc(imP_CREATE_FAMILY_TABLE, outfile);
  322.     putc(sz, outfile);
  323.     putc(1, outfile);
  324.     putc(0, outfile);
  325.     fputs(c, outfile);
  326.     putc(0, outfile);
  327. }
  328.  
  329. static void
  330. IMAGEN_setfont(sz) 
  331.     int sz;
  332. {
  333.     IMAGEN_hchar = sz * 5;
  334.     IMAGEN_wchar = IMAGEN_hchar / 2;
  335.     IMAGEN_blofs = IMAGEN_hchar / 3;
  336.     putc(imP_SET_FAMILY, outfile);
  337.     putc(sz, outfile);
  338.     putc(imP_SET_SP, outfile);
  339.     IMAGEN_putwd(IMAGEN_wchar);
  340.     putc(imP_SET_IL, outfile);
  341.     IMAGEN_putwd(IMAGEN_hchar);
  342. }
  343.